home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / windowtc.arc / QDEMO10.C < prev    next >
Text File  |  1987-06-20  |  12KB  |  339 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <dos.h>
  6. #include <conio.h>
  7. #include <w1.h>
  8. #include <windprot.h>
  9. #include <color.h>
  10.  
  11. #define WAIT 15000
  12. /*===============================================================================*/
  13. /*  Qdemo.c - Demonstration program for Q screen utilities  ver 1.0, 6-1-87      */
  14. /*  Demo has been programmed for All Cards and any column mode.  If you want to  */
  15. /*  try 40 column mode, set crtcolumns to 40 in main. This does not set your     */
  16. /*  machine to 40 column mode. This must be done by the DOS mode command.        */
  17. /*                                                                               */
  18. /* AUTHORS: Turbo Pascal version -- (C) 86,87 Jim H. Lemay                       */
  19. /*          Turbo C version -- (C) 1987 Mike Mlachak                             */
  20. /* DATE:    6-1-87                                                               */
  21. /* VERSION: 1.0                                                                  */
  22. /* COMMENTS: Must be compiled in SMALL model and linked with WIND1x.lib          */
  23. /*===============================================================================*/
  24.  
  25. typedef char str80[80];
  26.  
  27.     int          row, rows, col, cols, ctr, step, rstep, colmax, count,
  28.                  attrib, i, j, crtcols;
  29.     int          hidecursor, oldcursor, fgrnd, bgrnd;
  30.     int          brdrattr, wndwattr;
  31.     char         savedblock[4000], popupblock[4000];
  32.     int          blkrow, blkcol;
  33.     int          crtcolumns;               /*  number of CRT columns  */
  34.     int          tattr;
  35.     int          coll[3], colr[3];
  36.     char         strng[75], numstr[75];
  37.     double       rnum;
  38.  
  39.     extern void qinit(void);
  40.     int random(int);
  41.  
  42. /*  These are double lines for qbox  */
  43.  
  44.  
  45.    static str80 data[9] = {
  46.        "1",
  47.        "22", 
  48.        "333", 
  49.        " Q Screen Utilities ",
  50.        "Odd  Length",
  51.        "Even  Length",
  52.        "18 characters wide", 
  53.        "19 characters width",
  54.        "Margin to Margin width"};
  55.  
  56. /*  qbox is an application of Q screen utilities.  It can make fast pop up menus.
  57.     Together with qstore/qrestore, you can do several windows at one time.                */
  58.  
  59.  
  60.  
  61. void main(void)
  62. {
  63. /*  --- Set up data ---  */
  64.   qinit(); /*  << <<  Required intializing statement !!  */
  65.   crtcolumns = 80;
  66.   crtcols = crtcolumns;
  67.   hidecursor = 8192;
  68.  
  69. /*  --- Initial screen ---  */
  70.   oldcursor = cursorchange(hidecursor);
  71.   qfill(1, 1, 25, crtcols, (BLUE << 4) + WHITE, ' '); /*   Clear Screen  */
  72.   qwritecv(11, 1, crtcols, (BLUE << 4) + YELLOW, data[3]);
  73.   qwritec(13, 1, crtcols, -1, "Your screen is about to explode.");
  74.   qwritec(14, 1, crtcols, -1, "Hold on to your seat ...");
  75.   sleep(4);
  76.  
  77. /*  --- Explosion of Boxes ---  */
  78.   qfill(11, 1, 4, crtcols, -1, ' '); /*   Clear Lines  */
  79.   qattr(1, 1, 25, crtcols, LIGHTGRAY << 4); /*   Change screen attribute  */
  80.   ctr = crtcols / 2;
  81.   for (step = 2; step <= ctr - 2; step++) {
  82.      if (step > 24)
  83.         rstep = 12;
  84.      else
  85.         rstep = step >> 1;
  86.      for (count = 1; count <= 20; count++) {
  87.         row = 13 - rstep + random(rstep + 2);
  88.         rows = rstep;
  89.         cols = rstep + rstep + (rstep >> 2);
  90.         if (step <= 24)
  91.            col = ctr - cols + random(cols + 1);
  92.         else
  93.            col = ctr - 1 - step + random(step + step - 22);
  94.       fgrnd = random(16);
  95.       bgrnd = random(8);
  96.       if (bgrnd == fgrnd)
  97.          fgrnd = fgrnd + 1;
  98.       attrib = (bgrnd << 4) + fgrnd;
  99.       qfill(row,col,row,cols,attrib,'▓');
  100.     }  /* for count = 1*/
  101.   } /* for step = 2,..etc */
  102.  
  103.   qfillc(10, 1, crtcols, 6, 34, RED << 4, ' ');
  104.   qfillc(11, 1, crtcols, 4, 30, BROWN << 4, ' ');
  105.   tattr = (RED << 4) + YELLOW;
  106.   qwritecv(12, 1, crtcols, tattr, data[3]);
  107.   qwritec(13, 1, crtcols, tattr, "Turbo-C  Version 1.0");
  108.  
  109.   /*  --- Save Screen for Page Demo ---  */
  110.   if (maxpage > 0)
  111.   {
  112.     qstore(1, 1, 25, crtcols, savedblock);
  113.     qwritepage(1);
  114.     qrestore(1, 1, 25, crtcols, savedblock);
  115.     qwritepage(0);
  116.   }
  117.   /*  --- End of Save Screen ---  */
  118.   sleep(2);
  119.   tattr = (BLUE << 4) + WHITE;
  120.   qwritec(6, 1, crtcols, tattr, " qwrite will write with new attributes ");
  121.   qwritec(7, 1, crtcols, tattr, " that you specify direct to the screen.");
  122.   sleep(3);
  123.   qwritec(18, 1, crtcols, -1, " qwrite will also use existing attributes ");
  124.   qwritec(19, 1, crtcols, -1, "    when you do not even know or care.    ");
  125.                         /*  highlight the word 'existing'  */
  126.   qattrc(18, 6, crtcols + 5, 1, 10, (LIGHTRED << 4) + WHITE);
  127.   sleep(4);
  128.   qwritec(21, 1, crtcols, tattr, " Say Goodbye to this screen. ");
  129.   sleep(2);
  130.   /*  --- Disintigrate Screen ---  */
  131.  
  132.   for (i = 1; i <=7500; i++) {
  133.     row = random(25) +1;
  134.     col = random(crtcols) + 1;
  135.     qfill(row,col,1,1,BLACK, ' ');
  136.   }
  137.  
  138. /*  --- Qwrite with Reals Demo ---  */
  139.   qfill(1, 1, 25, crtcols, YELLOW, ' '); /*   Clear Screen  */
  140.   qwritec(2, 1, crtcols, -1, "qwritev with TURBO-C's sprintf will write");
  141.   qwritec(3, 1, crtcols, -1, "reals and integers faster:");
  142.   sleep(4);
  143.   rnum = 1.2345678901;
  144.   for (col = 0; col <= (crtcols / 20) - 1; col++)  {
  145.      for (row = 5; row <= 24; row++) {
  146.         rnum = rnum + 1.0;
  147.         sprintf(numstr,"%e",rnum);
  148.         qwritev(row, col * 20 + 4, -1, numstr);
  149.      }
  150.   }
  151.   sleep(5);
  152.  
  153. /*  --- Centering Demo ---  */
  154.   qfill(1, 1, 25, crtcols, LIGHTGRAY << 4, ' '); /*   Clear Screen  */
  155.   qwritec(2, 1, crtcols, -1, "qwritec and qwritecv will automatically");
  156.   qwritec(3, 1, crtcols, -1, "center your data ...");
  157.   qwritec(4, 1, crtcols, -1, "(ODD breaks are shifted to the left.)");
  158.   sleep(4);
  159.  
  160.   /*  - Set up columns for varying column modes -  */
  161.   coll[1] = 1;
  162.   colr[1] = crtcols;
  163.   if (crtcols < 80) {
  164.      coll[0] = coll[1];
  165.      coll[2] = crtcols / 2;
  166.      colr[0] = colr[1];
  167.      colr[2] = crtcols / 2;
  168.   }
  169.   else {
  170.      coll[0] = 3;
  171.      colr[0] = 26;
  172.      coll[2] = crtcols - 14;
  173.      colr[2] = crtcols - 14;
  174.   }
  175.  
  176.   qwritec(7, coll[0], colr[0], -1, "between margins ...");
  177.   qbox(8, (coll[0] + (colr[0] >> 1)) - 14, 15, 26, WHITE, LIGHTGRAY, doublebrdr);
  178.   sleep(2);
  179.   for (row = 11; row <= 19; row++)
  180.      qwritecv(row, coll[0], colr[0], -1, data[row - 11]);
  181.   sleep(2);
  182.  
  183.   qwritec(7, coll[1], colr[1], -1, "between two columns ...");
  184.   qfillc(9, coll[1], colr[1], 13, 24, YELLOW, ' '); /*   Clear window  */
  185.   for (row = 9; row <= 21; row++)
  186.      qwritec(row, coll[1], colr[1], -1, "><"); /*   Show two columns   */
  187.   sleep(2);
  188.   for (row = 11; row <= 19; row++)
  189.      qwritecv(row, coll[1], colr[1], LIGHTRED, data[row - 11]);
  190.   sleep(2);
  191.  
  192.   qwritec(7, coll[2], colr[2], -1, "or on a center line ...");
  193.   qfillc(8, coll[2], colr[2], 15, 27, LIGHTGRAY << 4, ' '); /*   Clear window  */
  194.   for (row = 9; row <= 21; row++) /*   Show center line   */
  195.      qwritec(row, coll[2], colr[2], (LIGHTGRAY << 4) + WHITE, "|");
  196.   sleep(2);
  197.   for (row = 11; row <= 19; row++)
  198.      qwritecv(row, coll[2], colr[2], -1, data[row - 11]);
  199.   sleep(5);
  200.  
  201. /*  --- Qfill Demo ---  */
  202.   qfill(1, 1, 25, crtcols, WHITE, ' '); /*   Clear Screen  */
  203.   qwritec(2, 1, crtcols, -1, "qfill as well as qattr can fill");
  204.   qwritec(3, 1, crtcols, -1, "your screen in several ways.");
  205.   sleep(3);
  206.  
  207.   qwritec(7, 1, crtcols, -1, "by rows ...");
  208.   sleep(2);
  209.   for (row = 9; row <= 24; row++)
  210.      qfill(row, 2, 1, crtcols - 2, 9 + row, (char)(row + 56)); 
  211.   sleep(3);
  212.  
  213.   qfill(7, 1, 19, crtcols, WHITE, ' '); /*   Clear Lines  */
  214.   qwritec(7, 1, crtcols, -1, "by columns ..."); 
  215.   sleep(2);
  216.   for (col = 2; col <= crtcols - 2; col++)
  217.      qfill(9, col, 16, 1, 16 + col, (char)(col + 63));
  218.   sleep(3);
  219.  
  220.   qfill(7, 1, 19, crtcols, WHITE, ' '); /*   Clear Lines  */
  221.   qwritec(7, 1, crtcols, -1, "or by row-by-column blocks ...");
  222.   sleep(2);
  223.   qfill(9, 2, 16, crtcols - 2, (BLUE << 4) + YELLOW, '!');
  224.   sleep(4);
  225.  
  226. /*  --- Qbox demo ---  */
  227.   qfill(1, 1, 25, crtcols, LIGHTGRAY << 4, ' '); /*   Clear Screen  */
  228.   qwritec(2, 1, crtcols, -1, "qbox is an application procedure made");
  229.   qwritec(3, 1, crtcols, -1, "from qwritev and qfill.  Together they");
  230.   qwritec(4, 1, crtcols, -1, "can make windows with borders easy.");
  231.   sleep(3);
  232.   qwritec(14, 1, crtcols, -1, "How about 1000 of them? ... ");
  233.   sleep(2);
  234.   colmax = crtcols - 21;
  235.   for (i = 1; i <= 1000; i++) {
  236.      row = random(10) + 6;
  237.      col = random(colmax) + 2;
  238.      brdrattr = random(128);
  239.      wndwattr = random(128);
  240.      qbox(row, col, 10, 20, brdrattr, wndwattr, doublebrdr);
  241.   }
  242.   sleep(5);
  243.  
  244. /*  --- Block Transfer and PopUp Demo ---  */
  245.   qfill(1, 1, 25, crtcols, YELLOW, '?'); /*   Clear Screen  */
  246.   qfillc(10, 1, crtcols, 6, 40, BROWN << 4, ' '); /*   Clear Block  */
  247.   qwritec(11, 1, crtcols, -1, "qstore will save and restore");
  248.   qwritec(12, 1, crtcols, -1, "Row-by-Column blocks on your display.");
  249.   qwritec(13, 1, crtcols, -1, "It is so fast, I have to slow it down");
  250.   qwritec(14, 1, crtcols, -1, "so you can see it.");
  251.   sleep(4);
  252.   blkrow = 8;
  253.   blkcol = (crtcols / 2) - 9;
  254.   qstore(blkrow, blkcol, 10, 20, savedblock);
  255.   /*  --- Make a Pop Up Menu ---  */
  256.   qbox(blkrow, blkcol, 10, 20, (BLUE << 4) + YELLOW, (BLUE << 4) + BROWN, doublebrdr);
  257.   qwritec(blkrow + 4, blkcol, blkcol + 20, -1, "Pop Up");
  258.   qwritec(blkrow + 5, blkcol, blkcol + 20, -1, "Menu");
  259.   /*  --- End of Pop Up Menu ---  */
  260.   qstore(blkrow, blkcol, 10, 20, popupblock);
  261.   sleep(3);
  262.   colmax = crtcols - 20;
  263.   for (i = 1; i <= 30; i++) {
  264.     for (j = 0; j <=WAIT; j++);
  265.      qrestore(blkrow, blkcol, 10, 20, savedblock);
  266.      blkrow = random(15) + 1;
  267.      blkcol = random(colmax) + 1;
  268.      qstore(blkrow, blkcol, 10, 20, savedblock);
  269.      qrestore(blkrow, blkcol, 10, 20, popupblock);
  270.   }
  271.  
  272. /*  --- Page Demo ---  */
  273.   if (maxpage > 0) {
  274.      qpage(1);
  275.      qwritepage(1);
  276.      tattr = (BLUE << 4) + YELLOW;
  277.      qwritec(20, 1, crtcols, tattr, " Remember this page?  ");
  278.      qwritec(21, 1, crtcols, tattr, " It wasn't destroyed, but saved using "); 
  279.      qwritec(22, 1, crtcols, tattr, " qstore/qrestore and placed on a new page. ");
  280.      sleep(6);
  281.      qwritepage(0); 
  282.      qpage(0);
  283.   } 
  284.  
  285. /*  --- Attribute Demo ---  */
  286.   qfill(1, 1, 25, crtcols, (GREEN << 4) + GREEN, ' '); /*   Clear Screen  */
  287.   tattr = (GREEN << 4) + WHITE;
  288.   qwritec(2, 1, crtcols, tattr, "Q Screen Utilities is hiding strings on");
  289.   qwritec(3, 1, crtcols, tattr, "your screen ...");
  290.   cols = crtcols / 20; 
  291.   if (qwait == 0)
  292.      tattr = 0; 
  293.   else
  294.      tattr = (GREEN << 4) + GREEN;
  295.   for (col = 0; col <= cols - 1; col++) 
  296.      for (row = 5; row <= 20; row++) 
  297.         qwritev(row, 20 * col + 1, tattr, data[3]);
  298.   sleep(3);
  299.  
  300.   qfill(2, 1, 2, crtcols, -1, ' '); /*   Clear Lines  */
  301.   tattr = (GREEN << 4) + BLACK;
  302.   qwritec(2, 1, crtcols, tattr, "qattr can show them -");
  303.   qwritec(3, 1, crtcols, tattr, "by merely changing the attribute!");
  304.   sleep(3);
  305.  
  306.   /*  --- Try using Turbo's color procedures this time ---  */
  307.   qattr(5, 1, 16, crtcols, tattr); /*   Reveal Data  */
  308.   sleep(3);
  309.  
  310.   qfill(2, 1, 2, crtcols, -1, ' '); /*   Clear Lines  */
  311.   qwritec(2, 1, crtcols, tattr, "Or even just emphasize what's seen ...");
  312.   for (i = 1; i <= 100; i++) {
  313.     row = random(16) + 5;
  314.     col = random(cols) * 20 + 1;
  315.     qattr(row, col, 1, 20, 46);
  316.     for (j=0; j<=WAIT-7500; j++);
  317.     qattr(row, col, 1, 20, 32);
  318.   }
  319.   for (i = 1; i <= cols; i++) /*   Emphasize Data  */
  320.     qattr(5 * i, (i - 1) * 20 + 1, 1, 20, (LIGHTGREEN << 4) + YELLOW);
  321.   tattr = wiattr(YELLOW,GREEN);
  322.   qwritec(24, 1, crtcols, tattr, " Original TEAMWARE concept (C) 86,87 James H. LeMay ");
  323.   qwritec(23, 1, crtcols, tattr, " TURBO-C Version (C) 1987 Michael G. Mlachak ");
  324.   gotorc(21, 1);
  325.   oldcursor = cursorchange(oldcursor);
  326. }
  327.  
  328. int random(seed)
  329. {
  330.   int hold;
  331.  
  332.      hold= rand();
  333.      if (hold > 127)
  334.        hold = hold % 127;
  335.      hold = hold % seed;
  336.    return(hold);
  337. }
  338.  
  339.